{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6cce5e50",
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'FakeProvider' from 'qiskit.providers.fake_provider' (/root/miniconda3/envs/xs/lib/python3.10/site-packages/qiskit/providers/fake_provider/__init__.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# 导入必要的库\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mqiskit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mproviders\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfake_provider\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m FakeProvider\n\u001b[1;32m      3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mqiskit\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mproviders\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfake_provider\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m FakeBackend\n\u001b[1;32m      4\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mwarnings\u001b[39;00m\n",
      "\u001b[0;31mImportError\u001b[0m: cannot import name 'FakeProvider' from 'qiskit.providers.fake_provider' (/root/miniconda3/envs/xs/lib/python3.10/site-packages/qiskit/providers/fake_provider/__init__.py)"
     ]
    }
   ],
   "source": [
    "# 导入必要的库\n",
    "from qiskit.providers.fake_provider import FakeProvider\n",
    "from qiskit.providers.fake_provider import FakeBackend\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "# 列出所有可用的模拟后端\n",
    "fake_provider = FakeProvider()\n",
    "backends = fake_provider.backends()\n",
    "\n",
    "print(\"可用的模拟后端:\")\n",
    "for backend in backends[:10]:  # 显示前10个后端\n",
    "    print(f\"- {backend.name}\")\n",
    "\n",
    "# 选择一个可用的后端（例如第一个）\n",
    "if backends:\n",
    "    backend = backends[0]\n",
    "    print(f\"\\n使用后端: {backend.name}\")\n",
    "    \n",
    "    # 获取后端的属性信息\n",
    "    properties = backend.properties()\n",
    "    \n",
    "    # 打印单量子比特测量重置时间\n",
    "    print(\"\\n=== 单量子比特测量重置时间 ===\")\n",
    "    if properties and hasattr(properties, 'qubits'):\n",
    "        for qubit_idx in range(min(5, len(properties.qubits))):  # 显示前5个量子比特\n",
    "            try:\n",
    "                # 查找readout_length参数（测量重置时间）\n",
    "                readout_length_params = [param for param in properties.qubits[qubit_idx] \n",
    "                                       if param.name == 'readout_length']\n",
    "                if readout_length_params:\n",
    "                    readout_reset_time = readout_length_params[0].value\n",
    "                    unit = readout_length_params[0].unit\n",
    "                    if unit == 'us':\n",
    "                        print(f\"量子比特 {qubit_idx}: {readout_reset_time:.2f} μs\")\n",
    "                    elif unit == 'ns':\n",
    "                        print(f\"量子比特 {qubit_idx}: {readout_reset_time:.2f} ns\")\n",
    "                    else:\n",
    "                        print(f\"量子比特 {qubit_idx}: {readout_reset_time} {unit}\")\n",
    "                else:\n",
    "                    print(f\"量子比特 {qubit_idx}: 无readout_length数据\")\n",
    "            except Exception as e:\n",
    "                print(f\"量子比特 {qubit_idx}: 无法获取数据\")\n",
    "    \n",
    "    # 打印双量子比特门(CX门)时间\n",
    "    print(\"\\n=== 双量子比特门时间 ===\")\n",
    "    if properties and hasattr(properties, 'gates'):\n",
    "        gates = properties.gates\n",
    "        cx_gates = [gate for gate in gates if gate.gate == 'cx']\n",
    "        \n",
    "        # 显示前10个CX门的时间\n",
    "        for i, gate in enumerate(cx_gates[:10]):\n",
    "            if len(gate.parameters) > 0:\n",
    "                gate_time_param = [param for param in gate.parameters if param.name == 'gate_time']\n",
    "                if gate_time_param:\n",
    "                    gate_time = gate_time_param[0].value\n",
    "                    unit = gate_time_param[0].unit\n",
    "                    qubits = gate.qubits\n",
    "                    if unit == 'ns':\n",
    "                        print(f\"CX门 {qubits[0]}-{qubits[1]}: {gate_time:.2f} ns\")\n",
    "                    elif unit == 'us':\n",
    "                        print(f\"CX门 {qubits[0]}-{qubits[1]}: {gate_time:.2f} μs\")\n",
    "                    else:\n",
    "                        print(f\"CX门 {qubits[0]}-{qubits[1]}: {gate_time} {unit}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
